package com.touzbi.hss.servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;

import com.touzbi.hibernate.util.HibernateUtil;
import com.touzbi.hss.beans.Soin;
import com.touzbi.hss.bo.SoinBO;
import com.touzbi.hss.dao.AbstractDAOFactory;
import com.touzbi.hss.dao.DAOFactory;

@WebServlet("/soins")
public class SoinServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String LIST_SOINS_NAMES_ATT = "list";
	private static final Object LIST_TITLE = "List Soins";
	private static final String LIST_TITLE_ATT = "title";
	private static final String SOIN_LIST_BO_ATT = "bo";
	private static final String SOIN_JSP = "/WEB-INF/list_soin.jsp";

	private static final String LIST_TYPE_ATTRIBUTE = "listType";
	private static final String LIST_TYPE = "soin-list";
	private static final String HEADER_TITLES_ATT = "titles";
	private static final String[] HEADER_TITLES = { "Content" };

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		AbstractDAOFactory daoFactory = new DAOFactory(
				HibernateUtil.getSessionFactory());
		Session session = daoFactory.getSession();
		session.beginTransaction();

		SoinBO soinBO = new SoinBO(daoFactory);
		List<Soin> listPatient = soinBO.getSoinList();

		session.getTransaction().commit();

		req.setAttribute(LIST_SOINS_NAMES_ATT, listPatient);
		req.setAttribute(LIST_TITLE_ATT, LIST_TITLE);
		req.setAttribute(SOIN_LIST_BO_ATT, soinBO);
		req.setAttribute(LIST_TYPE_ATTRIBUTE, LIST_TYPE);
		req.setAttribute(HEADER_TITLES_ATT, HEADER_TITLES);

		this.getServletContext().getRequestDispatcher(SOIN_JSP)
				.forward(req, resp);
	}
}
